package com.xsdl.memento;

public class Main {

    public static void main(String[] args) {
        InputText text = new InputText();
        SnapshotHolder holder = new SnapshotHolder();
        addContent(text, holder, "Hello");
        addContent(text, holder, " ");
        addContent(text, holder, "World");
        System.out.println(text.getContent());
        undo(text, holder);
        System.out.println(text.getContent());
        undo(text, holder);
        System.out.println(text.getContent());
    }

    private static void addContent(InputText text, SnapshotHolder holder, String content) {
        Snapshot snapshot = new Snapshot(text.getContent());
        holder.addSnapshot(snapshot);
        text.addContent(content);
    }

    private static void undo(InputText text, SnapshotHolder holder) {
        text.restoreFromSnapshot(holder.getSnapshot());
    }

}
